var mobId, mob, stats;
var 清怪 = true;
var 刷新地图 = true;
var 复活次数 = 11;
var 副本名称 = "组队任务_月妙";
var BOSS_1_id = 9300061;
var BOSS_1_血量倍率 = 60;
var 副本时限 = 1000 * 60 * 40;
var 实例地图 = [933001000];
var 准备地图 = 933000000;
var 退场倒计时 = 40;

function init() {}

function setup(f, a) {
    em.getProperties().clear();
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var c = em.newInstance(副本名称);
    for (var b = 0; b < 实例地图.length; b++) {
        var e = c.setInstanceMap(实例地图[b]);
        e.resetPQ(f);
        e.resetFully();
        e.killAllMonsters(清怪);
        e.respawn(刷新地图)
    }
    c.startEventTimer(副本时限);
    c.setProperty("FBtime", 副本时限);
    c.setProperty("FBname", 副本名称);
    c.setProperty("strMap", 准备地图);
    var d = em.getMonster(BOSS_1_id).getMobMaxHp() * BOSS_1_血量倍率;
    c.setProperty("BOSShp", d);
    return c
}

function onItemPickedUp(c, b, d) {
    if (d == 4000884) {
        var e = b.getAPI().getJobName(b.getAPI().getJob());
        var a = b.getName();
        c.getPlayers().forEach(function (f) {
            f.getAPI().getTopMsgFont("" + e + "<" + a + ">捡到1个迎月花种子，快去播种吧。", 3, 20, 13, 0)
        })
    }
}

function WarpTask(b, a) {
    eim.getPlayers().forEach(function (c) {
        c.scheduleWarpTask(4, b, a, false)
    })
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(实例地图[0]);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0);
    a.tryPartyQuest(1203)
}

function onPlayerKilled(b, a) {}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(d, c, b) {
    var a = 实例地图.indexOf(b);
    if (a < 0) {
        on玩家退场(d, c, false);
        return
    }
    switch (a) {
        case 0:
            break;
        case 1:
            break;
        default:
            break
    }
}

function 远古精灵(c, b, a, e) {
    var d = eim.getMapInstance(实例地图[c]);
    mobId = 9300039;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = 999999999;
    mob.setSize(b);
    mob.getChangedStats().matk = 50;
    mob.getChangedStats().watk = 50;
    mob.getChangedStats().acc = 9999999;
    mob.getChangedStats().level = 150;
    mob.heal();
    eim.registerMonster(mob);
    d.spawnMonsterOnGroundBelow(mob, new java.awt.Point(a, e))
}

function onMonsterKilled(a, b) {
    if (b == 9300061) {
        a.broadcastPlayerMsg(6, "月妙已死亡，任务失败！");
        a.getPlayers().forEach(function (c) {
            on玩家退场(a, c, true)
        })
    }
    return 1
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == BOSS_1_id) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function initPropArrayRandom(a, d, j, b, h) {
    var g = new Array();
    var k = h - b + 1;
    var c = (j - d) < (h - b) ? true : false;
    do {
        var f = randomNum(d, j);
        if (c || g.indexOf(f) < 0) {
            g.push(f);
            k--
        }
    } while (k);
    for (var e = b; e <= h; e++) {
        if (em.getProperty(a + "_" + e) == null) {
            em.setProperty(a + "_" + e, g[e - 1])
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPartyDisbanded(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, true);
    return 0
};